package com.zd.kids.ui.adapter;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zd.kids.DataBean.BookSeriesListDataBean;
import com.zd.kids.R;
import com.zd.kids.common.GlideUtil;
import com.zd.kids.common.ToastUtils;
import com.zd.kids.ui.activity.BookSeriesListActivity;
import com.zd.kids.ui.activity.BookUnitActivity;

import java.util.List;

/**
 * @ClassName: com.zd.kids.ui.adapter
 * @Description:
 * @Author: hyy
 * @Date: 2020/6/23
 * @Time: 7:52 PM
 */
public class BookSeriesAdapter extends BaseMultiItemQuickAdapter<BookSeriesListDataBean, BaseViewHolder> {

    public static final int VERTICAL_TYPE = 0;

    public static final int HORIZON_TYPE = 1;

    private String groupId;

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public BookSeriesAdapter(List<BookSeriesListDataBean> data) {
        super(data);

        addItemType(VERTICAL_TYPE, R.layout.activity_book_series_vertical_item);

        addItemType(HORIZON_TYPE, R.layout.activity_book_series_horizon_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, BookSeriesListDataBean item) {

        LinearLayout llRootview = helper.getView(R.id.ll_rootview);
        llRootview.setBackgroundResource(item.getViewBg());

        llRootview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (item.isCategory_status()) {
                    Intent intent = new Intent(mContext, BookUnitActivity.class);
                    intent.putExtra(BookSeriesListActivity.GROUP_ID_KEY, groupId);
                    intent.putExtra(BookSeriesListActivity.CATEGORY_ID_KEY, item.getId());
                    mContext.startActivity(intent);
                } else {
                    ToastUtils.getIntence().makeTextShow("請聯絡課程顧問激活");
                }

            }
        });

        ImageView imgContent = helper.getView(R.id.img_content);

        View viewLock = helper.getView(R.id.view_lock);

        TextView tvName = helper.getView(R.id.tv_name);

        GlideUtil.load(item.getImgPath(), imgContent, (int) mContext.getResources().getDimension(R.dimen.book_series_radius), item.getItemType() == VERTICAL_TYPE ? GlideUtil.RoundType.Top : GlideUtil.RoundType.RIGHT);

        tvName.setText(item.getTitle());

        viewLock.setVisibility(item.isCategory_status() ? View.GONE : View.VISIBLE);

    }

}
